export default class CustomPalette {
    private bpmnFactory: any;
    private create: any;
    private elementFactory: any;
    private translate: any;
    static $inject: string[];
    constructor(bpmnFactory: any, create: any, elementFactory: any, palette: any, translate: any) {
        this.bpmnFactory = bpmnFactory;
        this.create = create;
        this.elementFactory = elementFactory;
        this.translate = translate;

        palette.registerProvider(this);
    }

    getPaletteEntries() {
        const {
            bpmnFactory,
            create,
            elementFactory,
            translate
        } = this;

        function createHandle() {
            return function(event: any) {
                const businessObject = bpmnFactory.create("bpmn:UserTask");
                businessObject.name = "执行节点";
                businessObject.$attrs.customAttr = JSON.stringify({ type: "handle", typeName: "执行节点" });
                businessObject.$attrs.taskType = "Handle";
                const shape = elementFactory.createShape({
                    type: "bpmn:UserTask",
                    businessObject
                });
                console.log(shape); // 只在拖动或者点击时触发
                create.start(event, shape);
            };
        }

        function createApproval() {
            return function(event: any) {
                const businessObject = bpmnFactory.create("bpmn:UserTask");
                businessObject.name = "确认节点";
                businessObject.$attrs.customAttr = JSON.stringify({ type: "approval", typeName: "确认节点" });
                businessObject.$attrs.taskType = "Approval";
                const shape = elementFactory.createShape({
                    type: "bpmn:UserTask",
                    businessObject
                });
                console.log(shape); // 只在拖动或者点击时触发
                create.start(event, shape);
            };
        }

        function createStartEvent() {
            return function(event: any) {
                const businessObject = bpmnFactory.create("bpmn:StartEvent");
                businessObject.name = "开始";
                const shape = elementFactory.createShape({
                    type: "bpmn:StartEvent",
                    businessObject
                });
                console.log(shape); // 只在拖动或者点击时触发
                create.start(event, shape);
            };
        }

        function createEndEvent() {
            return function(event: any) {
                const businessObject = bpmnFactory.create("bpmn:EndEvent");
                businessObject.name = "结束";
                const shape = elementFactory.createShape({
                    type: "bpmn:EndEvent",
                    businessObject
                });
                console.log(shape); // 只在拖动或者点击时触发
                create.start(event, shape);
            };
        }

        /* function createCopy() {
            return function(event: any) {
                const businessObject = bpmnFactory.create("bpmn:UserTask");
                businessObject.name = "抄送节点";
                businessObject.$attrs.customAttr = JSON.stringify({ type: "copy", typeName: "抄送节点" });
                const shape = elementFactory.createShape({
                    type: "bpmn:UserTask",
                    businessObject
                });
                console.log(shape); // 只在拖动或者点击时触发
                create.start(event, shape);
            };
        } */

        return {
            'create.custom-handle': {
                group: 'model',
                className: 'icon-custom custom-handle',
                title: translate('执行节点'),
                action: {
                    dragstart: createHandle(),
                    click: createHandle()
                }
            },
            'create.custom-approval': {
                group: 'model',
                className: 'icon-custom custom-approval',
                title: translate('确认节点'),
                action: {
                    dragstart: createApproval(),
                    click: createApproval()
                }
            },
            'create.custom-start': {
                group: 'event',
                className: 'icon-custom custom-start',
                title: translate('开始'),
                action: {
                    dragstart: createStartEvent(),
                    click: createStartEvent()
                }
            },
            'create.custom-end': {
                group: 'event',
                className: 'icon-custom custom-end',
                title: translate('结束'),
                action: {
                    dragstart: createEndEvent(),
                    click: createEndEvent()
                }
            }
            /* 'create.custom-copy': {
                group: 'model',
                className: 'bpmn-icon-user-task',
                title: translate('创建一个抄送节点'),
                action: {
                    dragstart: createCopy(),
                    click: createCopy()
                }
            } */
        };
    }
}

CustomPalette.$inject = [
    'bpmnFactory',
    'create',
    'elementFactory',
    'palette',
    'translate'
];
